package com.pi.shisan.util.spipoint;

import com.pi.shisan.common.NumberUtil;

public class SpiToPointRotate180 extends BaseXyToSpi{

    //反转的话，y = 0时是result的最后一个， x = 0时是8位右侧的第一个
    @Override
    public void add(int x, int y) {
        checkXy(x,y);
        result[7 - y] |= 1 << x;
    }

    @Override
    public void put(int x, int y) {
        x = convert(x);
        y = convert(y);
        result[7 - y] |= 1 << x;
    }

    @Override
    public void put(int xy) {
        put(NumberUtil.toX(xy), NumberUtil.toY(xy));
    }

    @Override
    public void remove(int x, int y) {
        checkXy(x,y);
        result[7 - y] &= ~(1 << x);
    }

    @Override
    public void delete(int x, int y) {
        x = convert(x);
        y = convert(y);
        result[7 - y] &= ~(1 << x);
    }

    @Override
    public void delete(int xy) {
        delete(NumberUtil.toX(xy), NumberUtil.toY(xy));
    }

    @Override
    public String toString(){
        StringBuilder builder = new StringBuilder();
        for (int i = 7; i >= 0; i--) {
            for (int j = 0; j < 8; j++) {
                if (j > 0) {
                    builder.append(" ");
                }
                builder.append((1<<j&result[i])!=0?"◼":"○");
            }
            builder.append("\n");
        }
        return builder.toString();
    }

    public static void main(String[] args) {

        XyToSpiHolder toSpi = new SpiToPointRotate180();
        toSpi.put(0,0);
        toSpi.put(1,0);
        toSpi.put(2,4);
        toSpi.put(7,1);
        toSpi.delete(1,0);
        System.out.println(toSpi.toString());

    }
}
